Vue.component('yl-button', {
    template: `
    <span>
        <el-button :type="type" @click="Export" :loading="loading">
            <slot></slot>
        </el-button>
        <el-table id="ExportData" :data="data" style="display: none; width: 100%;margin-bottom: 20px;">
            <el-table-column label="序号"type="index"></el-table-column>
            <el-table-column prop="Supplier_Article_SerialNumber" label="供应商品内码"></el-table-column>
            <el-table-column prop="Article_SerialNumber" label="商品内码"></el-table-column>
            <el-table-column prop="Article_Specifications_SerialNumber" label="规格内码"></el-table-column>
            <el-table-column prop="Supplier_SerialNumber" label="供应商内码"></el-table-column>
            <el-table-column prop="Article_Name" label="商品名称"></el-table-column>
            <el-table-column prop="Specifications_Name" label="规格名称"></el-table-column>
            <el-table-column prop="Picture_URL" label="图片">
                <template v-slot="{row}">
                    {{row.Picture_URL? BASE_IMG +row.Picture_URL:'否'}}
                </template>
            </el-table-column>
            <el-table-column prop="Brand_Name" label="品牌名称"></el-table-column>
            <el-table-column prop="Brand_SerialNumber" label="品牌内码"></el-table-column>
            <el-table-column prop="Category_Name" label="类别"></el-table-column>
            <el-table-column prop="Category_SerialNumber" label="类别内码"></el-table-column>
            <el-table-column prop="Series_Name" label="系列"></el-table-column>
            <el-table-column prop="Series_SerialNumber" label="系列内码"></el-table-column>
            <el-table-column prop="Total_stock" label="今日上架库存"></el-table-column>
            <el-table-column prop="Stock_Remain" label="当日剩余库存"></el-table-column>
            <el-table-column prop="Stock_Sell" label="当日已售"></el-table-column>
            <el-table-column prop="Shelf" label="是否上架">
                <template v-slot="{row}">
                    {{row.Shelf=='0'?'是':'否'}}
                </template>
            </el-table-column>
            <el-table-column prop="Shelf_Date" label="上/下架操作时间"></el-table-column>
            <el-table-column label="导出时间">
                <template v-slot="{row}">
                    {{getYMDHMSDate()}}
                </template>
            </el-table-column>
        </el-table>
    </span>`,
    props: ['loading', 'data', 'type'],
    methods: {
        Export() {
            this.$emit('click')
        }
    }
})
new Vue({
    el: '#app',
    data() {
        return {
            radio1: '',
            form: {
                //SQLSerialNumber: "P_supplier_selection_article",
                SQLSerialNumber: "P_supplier_selection_article2",
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
                Article_Name: '',
                Supplier_SerialNumber: '',
                Brand_SerialNumber: '',
                // selection:false,//已选
                selection: '0',//已选
                Row_Status: '0',
                ExtensionCondition: '',
                Condition: ''
            },
            total: 0,
            tableData: [],	//表格数据
            brand: [],
            ExportData: [],//导出
            loading: false,
            defaultProps: {
                children: 'Children',
                label: 'Classify_Name',
                value: 'Classify_SerialNumber',
                multiple: true
            },
            business_article_classify: [],
            classify: [],
            supplier: [],
            multipleSelection: [],
            dialogVisible: false,
            dialogVisible1: true,
            form1: {
                Purchase_Unit_Price: '',
                Quantity: '',
            },
            form2: {},
            loading: false,
            table:true
        }
    },
    mounted() {
        if (getCookie('role')) {
            let roleObj = JSON.parse(getCookie('role'));
            this.form.Supplier_SerialNumber = roleObj.other;
        }
        this.getData();
        this.getList(this.form);//前端分页
    },
    methods: {
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        getData() {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableName`,
                data: {
                    Data: 'business_brand',
                    Condition: "Row_Status='0'"
                },
                success: function (Result) {
                    that.brand = Result
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/getAllClassify`,
                type: 'GET',
                success: function (data) {
                    that.classify = data
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        selectable(row) {
            return row.Other_SerialNumber == this.form.Supplier_SerialNumber;
        },
        handleSelectionChange(val) {//批量选品
            this.multipleSelection = val;
        },
        downloadTemplate(command) {
            if (command == "Article") {
                window.location.href = './download/导入商品模板表.新.xlsx';
            }
        },
        importTemplate(command) {
            if (command == "Article") {
                window.location.href = './import.html';
            }
        },
        handleBatchAdd() {//批量添加
            const that = this;
            if (this.multipleSelection.length > 0) {
                this.$confirm('是否将勾选的商品加入到已选商品中?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'info'
                }).then(() => {
                    //1.遍历已选查询对应数据
                    let sql = '';
                    this.multipleSelection.forEach(item => {
                        if (sql) {
                            sql = sql + "or Supplier_SerialNumber='" + that.form.Supplier_SerialNumber + "' and Article_Specifications_SerialNumber='" + item.Article_Specifications_SerialNumber + "' \r\n"
                        } else {
                            sql = "Supplier_SerialNumber='" + that.form.Supplier_SerialNumber + "' and Article_Specifications_SerialNumber='" + item.Article_Specifications_SerialNumber + "' \r\n";
                        }
                    });
                    $.ajax({
                        headers: requestHeaders(),
                        type: 'POST',
                        url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                        data: {
                            Data: "business_supplier_article",
                            Condition: "(" + sql + ")",
                        },
                        success: function (business_supplier_article) {
                            let Add = { business_supplier_article: [] };
                            let Modify = { business_supplier_article: [] }
                            for (let i = 0; i < that.multipleSelection.length; i++) {
                                let obj = that.multipleSelection[i];
                                let is = true;
                                for (let j = 0; j < business_supplier_article.length; j++) {
                                    if (obj.Article_Specifications_SerialNumber == business_supplier_article[j].Article_Specifications_SerialNumber) {//存在
                                        business_supplier_article[j].Row_Status = '0';
                                        Modify.business_supplier_article.push(business_supplier_article[j]);
                                        is = false;
                                        break;
                                    }
                                }
                                if (is) {
                                    Add.business_supplier_article.push({
                                        Supplier_Article_SerialNumber: (that.form.Supplier_SerialNumber + '-' + obj.Article_Specifications_SerialNumber),
                                        Supplier_SerialNumber: that.form.Supplier_SerialNumber,
                                        Article_SerialNumber: obj.Article_SerialNumber,
                                        Article_Specifications_SerialNumber: obj.Article_Specifications_SerialNumber,
                                        Shelf: '0',
                                        Shelf_Date: getYMDHMSDate(),
                                    })
                                }
                            }
                            $.ajax({
                                headers: requestHeaders(),
                                type: 'POST',
                                url: `${BASE_URL2}/generalBusiness/generalSave`,
                                data: {
                                    Data: JSON.stringify({
                                        Modify, Add
                                    })
                                },
                                success: function (Result) {
                                    if (Result.Status == 'success') {
                                        that.$message({
                                            type: 'success',
                                            message: '选品成功!'
                                        });
                                    } else {
                                        that.$message.error("系统繁忙，请重试")
                                    }
                                    that.getList(that.form);
                                },
                                complete: function (XMLHttpRequest) {
                                    requestPretreatment(XMLHttpRequest);
                                },
                                dataType: "json"
                            });
                        },
                        complete: function (XMLHttpRequest) {
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    });
                }).catch(() => { });
            } else {
                this.$message({
                    type: 'warning',
                    message: '至少要选择1个商品!'
                });
            }
        },
        select(row) {//选品
            if (row.Row_Status1 == '2'||row.Row_Status2=='9') {

            } else if (row.Row_Status == '0') {
                this.handleAdd(row);
            } else {
                this.form2 = row;
                this.dialogVisible = true;
            }
        },
        sumbit() {
            const that = this;
            this.loading = true;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                data: {
                    Data: "business_supplier_article",
                    Condition: "Article_Specifications_SerialNumber='" + that.form2.Article_Specifications_SerialNumber
                        + "' and Supplier_SerialNumber='" + that.form.Supplier_SerialNumber + "'"
                },
                success: function (business_supplier_article) {
                    let data = {},Modify = {};
                    if (business_supplier_article.length == 0) {//不存在
                        business_supplier_article.push({
                            Supplier_Article_SerialNumber: (that.form.Supplier_SerialNumber + '-' + that.form2.Article_Specifications_SerialNumber),
                            Supplier_SerialNumber: that.form.Supplier_SerialNumber,
                            Article_SerialNumber: that.form2.Article_SerialNumber,
                            Article_Specifications_SerialNumber: that.form2.Article_Specifications_SerialNumber,
                            Shelf: '0',
                            Shelf_Date: getYMDHMSDate(),
                            Row_Status: '99'
                        })
                        data.business_supplier_article = business_supplier_article;
                    } else {
                        business_supplier_article[0].Row_Status = '99';
                        Modify.business_supplier_article = business_supplier_article;
                    }
                    //采购价格单
                    let business_purchase_unitprice = [{
                        Purchase_Unit_Price_SerialNumber: '',
                        Start_Date: getYMDDate(),
                        End_Date: '',
                        Enterprise_Info_SerialNumber: '',
                        Children: {
                            business_purchase_unitprice_detail: [{
                                Purchase_Unit_Price_Detail_SerialNumber: '',
                                Purchase_Unit_Price_SerialNumber: '',
                                Supplier_Article_SerialNumber: that.form.Supplier_SerialNumber + '-' + that.form2.Article_Specifications_SerialNumber,
                                Brand_SerialNumber: that.form2.Brand_SerialNumber,
                                Purchase_Unit_Price: that.form1.Purchase_Unit_Price,
                                Row_Status: '2'
                            }],
                        }
                    }]
                    data.business_purchase_unitprice = business_purchase_unitprice;
                    //库存单
                    let business_supplier_article_stock = [{
                        Supplier_Article_Stock_SerialNumber: '',
                        Start_Date: getYMDDate(),
                        End_Date: '',
                        Enterprise_Info_SerialNumber: '',
                        Children: {
                            business_supplier_article_stock_detail: [{
                                Supplier_Article_Stock_Detail_SerialNumber: '',
                                Supplier_Article_Stock_SerialNumber: '',
                                Supplier_Article_SerialNumber: that.form.Supplier_SerialNumber + '-' + that.form2.Article_Specifications_SerialNumber,
                                Brand_SerialNumber: that.form2.Brand_SerialNumber,
                                Quantity: that.form1.Quantity
                            }]
                        }
                    }]
                    data.business_supplier_article_stock = business_supplier_article_stock;
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({ Add: data,Modify })
                        },
                        success: function (Result) {
                            if (Result.Status == 'success') {
                                that.$message({
                                    type: 'success',
                                    message: '选品成功!'
                                });
                            } else {
                                that.$message.error("系统繁忙，请重试")
                            }
                            that.getList(that.form);
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false;
                            that.dialogVisible = false;
                            requestPretreatment(XMLHttpRequest);
                        },
                        dataType: "json"
                    })
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            })
            // let data = {}
            // if (this.form1.Purchase_Unit_Price) {
            //     let business_purchase_unitprice = [{
            //         Purchase_Unit_Price_SerialNumber: '',
            //         Start_Date: getYMDDate(),
            //         End_Date: '',
            //         Enterprise_Info_SerialNumber: '',
            //         Children: {
            //             business_purchase_unitprice_detail:[{
            //                 Purchase_Unit_Price_Detail_SerialNumber: '',
            //                 Purchase_Unit_Price_SerialNumber: '',
            //                 Supplier_Article_SerialNumber: this.form.Supplier_SerialNumber+'-'+this.form2.Article_Specifications_SerialNumber,
            //                 Brand_SerialNumber: this.form2.Brand_SerialNumber,
            //                 Purchase_Unit_Price: this.form1.Purchase_Unit_Price,
            //                 Row_Status:'2'
            //             }],
            //         }
            //     }]
            //     data.business_purchase_unitprice = business_purchase_unitprice;
            // }
            // if (this.form1.Quantity) {
            //     let business_supplier_article_stock = [{
            //         Supplier_Article_Stock_SerialNumber: '',
            //         Start_Date: getYMDDate(),
            //         End_Date: '',
            //         Enterprise_Info_SerialNumber: '',
            //         Children: {
            //             business_supplier_article_stock_detail:[{
            //                 Supplier_Article_Stock_Detail_SerialNumber: '',
            //                 Supplier_Article_Stock_SerialNumber: '',
            //                 Supplier_Article_SerialNumber: this.form.Supplier_SerialNumber+'-'+this.form2.Article_Specifications_SerialNumber,
            //                 Brand_SerialNumber: this.form2.Brand_SerialNumber,
            //                 Quantity: this.form1.Quantity
            //             }]
            //         }
            //     }]
            //     data.business_supplier_article_stock = business_supplier_article_stock;
            // } 
            // $.ajax({
            //     headers: requestHeaders(),
            //     url: `${BASE_URL2}/generalBusiness/generalSave`,
            //     type: 'POST',
            //     data: {
            //         Data: JSON.stringify({ Add: data })
            //     },
            //     success: function (res) {
            //         that.handleAdd(that.form2);
            //         // if (res.Status === 'success') {
            //         //     $.ajax({//更新今日执行单
            //         //         headers: requestHeaders(),
            //         //         url: `${BASE_URL2}/article/generateDailyInventory`,
            //         //         type: 'GET',
            //         //         complete: function (XMLHttpRequest) {
            //         //             $.ajax({//更新今日执行单
            //         //                 headers: requestHeaders(),
            //         //                 url: `${BASE_URL2}/article/generateDailyInventory`,
            //         //                 type: 'GET',
            //         //                 complete: function (XMLHttpRequest) {
            //         //                     $.ajax({//更新今日执行单
            //         //                         headers: requestHeaders(),
            //         //                         url: `${BASE_URL2}/article/generateDailyArticlePurchasePrice`,
            //         //                         type: 'GET',
            //         //                         complete: function (XMLHttpRequest) {
            //         //                             that.handleAdd(that.form2);   
            //         //                         }
            //         //                     })
            //         //                 }
            //         //             })
            //         //         }
            //         //     })
            //         // }else{
            //         //     that.handleAdd(that.form2);
            //         // }
            //     },
            //     complete: function (XMLHttpRequest) {
            //         requestPretreatment(XMLHttpRequest);
            //     },
            //     dataType: "json"
            // })
        },
        tableName(Supplier_Article_SerialNumber, callback) {
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/member/getMemberPoint`,
                data: {
                    Data: JSON.stringify([{
                        tableName: 'business_purchase_unitprice_detail',
                        Condition: window.btoa(unescape(encodeURIComponent("Supplier_Article_SerialNumber='" + Supplier_Article_SerialNumber + "'"))),
                    }, {
                        tableName: 'business_daily_purchase_unitprice',
                        Condition: window.btoa(unescape(encodeURIComponent("Supplier_Article_SerialNumber='" + Supplier_Article_SerialNumber + "' AND Execute_Date='" + getYMDDate() + "'"))),
                    }, {
                        tableName: 'business_sales_unitprice_detail',
                        Condition: window.btoa(unescape(encodeURIComponent("Supplier_Article_SerialNumber='" + Supplier_Article_SerialNumber + "'"))),
                    }, {
                        tableName: 'business_daily_execute_unitprice',
                        Condition: window.btoa(unescape(encodeURIComponent("Supplier_Article_SerialNumber='" + Supplier_Article_SerialNumber + "' AND Execute_Date='" + getYMDDate() + "'"))),
                    }, {
                        tableName: 'business_supplier_article_stock_detail',
                        Condition: window.btoa(unescape(encodeURIComponent("Supplier_Article_SerialNumber='" + Supplier_Article_SerialNumber + "'"))),
                    }, {
                        tableName: 'business_daily_execute_stock',
                        Condition: window.btoa(unescape(encodeURIComponent("Supplier_Article_SerialNumber='" + Supplier_Article_SerialNumber + "' AND Execute_Date='" + getYMDDate() + "'"))),
                    }, {
                        tableName: 'business_activity_article',
                        Condition: window.btoa(unescape(encodeURIComponent("Supplier_Article_SerialNumber='" + Supplier_Article_SerialNumber + "'"))),
                    }]),
                },
                success: function ({ business_purchase_unitprice_detail, business_daily_purchase_unitprice, business_sales_unitprice_detail, business_daily_execute_unitprice, business_supplier_article_stock_detail, business_daily_execute_stock, business_activity_article }) {
                    callback(business_purchase_unitprice_detail, business_daily_purchase_unitprice, business_sales_unitprice_detail, business_daily_execute_unitprice, business_supplier_article_stock_detail, business_daily_execute_stock, business_activity_article);
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            })
        },
        handleAdd(row) {//添加
            const that = this;
            let Supplier_Article_SerialNumber = row.Supplier_Article_SerialNumber;
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
                data: {
                    Data: "business_supplier_article",
                    Condition: "Article_Specifications_SerialNumber='" + row.Article_Specifications_SerialNumber
                        + "' and Supplier_SerialNumber='" + that.form.Supplier_SerialNumber + "'"
                },
                success: function (business_supplier_article) {
                    let data = {};
                    if (Supplier_Article_SerialNumber) {//取消
                        let business_activity_article1 = [];
                        // let sql = ""
                        // business_supplier_article.forEach(item=>{
                        //     if (sql) {
                        //         sql += "OR Article_Specifications_SerialNumber='"+item.Article_Specifications_SerialNumber+"' AND Row_Status='0'\r\n";
                        //     } else {
                        //         sql = "Article_Specifications_SerialNumber='"+item.Article_Specifications_SerialNumber+"' AND Row_Status='0'\r\n";
                        //     }
                        // })
                        
                        // $.ajax({//查询账户信息
                        //     headers: requestHeaders(),
                        //     url: `${BASE_URL2}/member/getMemberPoint`,
                        //     type: 'POST',
                        //     data: {
                        //         Data: JSON.stringify([{
                        //             tableName: 'business_activity_article',
                        //             Condition: window.btoa(unescape(encodeURIComponent(sql))),
                        //         }]),
                        //     },
                        //     success: function ({business_activity_article}) {
                        //         business_activity_article.forEach(item=>{
                        //             item.Row_Status = '1';
                        //         })
                        //         business_activity_article1 = business_activity_article
                                that.tableName(Supplier_Article_SerialNumber, (business_purchase_unitprice_detail, business_daily_purchase_unitprice, business_sales_unitprice_detail, business_daily_execute_unitprice, business_supplier_article_stock_detail, business_daily_execute_stock, business_activity_article) => {
                                    business_purchase_unitprice_detail.forEach(item => {
                                        item.Row_Status = '1';
                                    });
                                    business_daily_purchase_unitprice.forEach(item => {
                                        item.Row_Status = '1';
                                    });
                                    business_sales_unitprice_detail.forEach(item => {
                                        item.Row_Status = '1';
                                    });
                                    business_daily_execute_unitprice.forEach(item => {
                                        item.Row_Status = '1';
                                    });
                                    business_supplier_article_stock_detail.forEach(item => {
                                        item.Row_Status = '1';
                                    });
                                    business_daily_execute_stock.forEach(item => {
                                        item.Row_Status = '1';
                                    });
                                    // if (row.Other_SerialNumber!=that.form.Supplier_SerialNumber) {
                                        business_activity_article.forEach(item => {
                                            item.Row_Status = '1';
                                        })
                                        business_activity_article1 = business_activity_article;
                                    // }
                                    
                                    business_supplier_article[0].Row_Status = '1'
                                    data = {
                                        Data: JSON.stringify({
                                            Modify: {
                                                business_supplier_article,
                                                business_purchase_unitprice_detail,
                                                business_daily_purchase_unitprice,
                                                business_sales_unitprice_detail,
                                                business_daily_execute_unitprice,
                                                business_supplier_article_stock_detail,
                                                business_daily_execute_stock,
                                                business_activity_article:business_activity_article1
                                            }
                                        })
                                    }
                                    $.ajax({
                                        headers: requestHeaders(),
                                        type: 'POST',
                                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                                        data,
                                        success: function (Result) {
                                            if (Result.Status == 'success') {
                                                that.$message({
                                                    type: 'success',
                                                    message: Supplier_Article_SerialNumber ? '取消成功' : '选品成功!'
                                                });
                                            } else {
                                                that.$message.error("系统繁忙，请重试")
                                            }
                                            that.getList(that.form);
                                        },
                                        complete: function (XMLHttpRequest) {
                                            that.dialogVisible = false;
                                            that.loading = false;
                                            requestPretreatment(XMLHttpRequest);
                                        },
                                        dataType: "json"
                                    });
                                })
                                
                        //     },
                        //     complete: function (XMLHttpRequest) {
                        //         requestPretreatment(XMLHttpRequest, false, (err) => {
                        //             if (err == 'error') {
                        //                 that.$message.error("系统繁忙!")
                        //             }
                        //         });
                        //     },
                        //     dataType: "json"
                        // });
                        //价格单状态改成1
                        
                    } else {//添加
                        if (business_supplier_article.length == 1) {//存在
                            business_supplier_article[0].Row_Status = '0'
                            data = {
                                Data: JSON.stringify({ Modify: { business_supplier_article } })
                            }
                        } else
                            if (business_supplier_article.length == 0) {//不存在
                                business_supplier_article.push({
                                    Supplier_Article_SerialNumber: (that.form.Supplier_SerialNumber + '-' + row.Article_Specifications_SerialNumber),
                                    Supplier_SerialNumber: that.form.Supplier_SerialNumber,
                                    Article_SerialNumber: row.Article_SerialNumber,
                                    Article_Specifications_SerialNumber: row.Article_Specifications_SerialNumber,
                                    Shelf: '0',
                                    Shelf_Date: getYMDHMSDate(),
                                })
                                data = {
                                    Data: JSON.stringify({ Add: { business_supplier_article } })
                                }
                            }
                        $.ajax({
                            headers: requestHeaders(),
                            type: 'POST',
                            url: `${BASE_URL2}/generalBusiness/generalSave`,
                            data,
                            success: function (Result) {
                                if (Result.Status == 'success') {
                                    that.$message({
                                        type: 'success',
                                        message: Supplier_Article_SerialNumber ? '取消成功' : '选品成功!'
                                    });
                                } else {
                                    that.$message.error("系统繁忙，请重试")
                                }
                                that.getList(that.form);
                            },
                            complete: function (XMLHttpRequest) {
                                that.dialogVisible = false;
                                that.loading = false;
                                requestPretreatment(XMLHttpRequest);
                            },
                            dataType: "json"
                        });
                    }

                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Add() {
            window.location.href = './add.html'
        },
        Edit(Article_SerialNumber, is = '0',Article_Specifications_SerialNumber) {
            sessionStorage.setItem("Article_SerialNumber", Article_SerialNumber)
            sessionStorage.setItem("is", is)
            if (Article_Specifications_SerialNumber) {
                sessionStorage.setItem("Article_Specifications_SerialNumber", Article_Specifications_SerialNumber)
            }
            window.location.href = './edit.html?Article_SerialNumber=' + Article_SerialNumber
        },
        examine() {//审核明细
            window.location.href = './log.html'
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        getList(form) {//换页方法
            const that = this
            let data = deepClone(form);
            data.Condition = window.btoa(unescape(encodeURIComponent(data.Supplier_SerialNumber + ",%" + data.Article_Name + "%")));
            let sql = "";
            if (data.Brand_SerialNumber) {
                sql = sql + "and business_article_info.Brand_SerialNumber = '" + data.Brand_SerialNumber + "'\r\n";
            }
            if (data.selection == '1') {
                sql = sql + "AND IFNULL(base_system_user_role.Other_SerialNumber,'') <> '" + data.Supplier_SerialNumber + "'\r\n"
            } else if (data.selection == '2') {
                sql = sql + "AND IFNULL(base_system_user_role.Other_SerialNumber,'') = '" + data.Supplier_SerialNumber + "'\r\n"
            }
            if (this.form.Row_Status == '1') {
                sql = sql + "AND IFNULL(business_purchase_unitprice_detail.Row_Status,'') = ''\r\n"
                    + "AND IFNULL(business_supplier_article.Row_Status,'1') = '0'"
            } else if (this.form.Row_Status == '2') {
                sql = sql + "AND IFNULL(business_purchase_unitprice_detail.Row_Status,'') = ''\r\n"
                    + "AND IFNULL(business_supplier_article.Row_Status,'1') = '1'"
            }
            if (this.business_article_classify.length > 0) {
                let str = "";
                this.business_article_classify.forEach(item => {
                    if (str) {
                        str = str + " or business_article_classify.Classify_SerialNumber = '" + item[item.length - 1] + "' \r\n"
                    } else {
                        str = "business_article_classify.Classify_SerialNumber = '" + item[item.length - 1] + "' \r\n"
                    }
                })
                sql = sql + " and (" + str + ") \r\n";
            }
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(sql)));
            $.ajax({
                headers: requestHeaders(),
                type: 'POST',
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                    that.table = false;
                    const timer = setTimeout(() => {
                        that.table = true;
                        clearTimeout(timer);
                    })
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Export() {
            if (this.multipleSelection.filter(i=>i.Other_SerialNumber==this.form.Supplier_SerialNumber||i.Row_Status1!='2'&&i.Row_Status=='0').length > 0) {
                this.$confirm('当前只会将已选中的或自建商品导出?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                }).then(() => {
                    const wb = XLSX.utils.book_new();
                    const ws_data = [["商品内码", "商品编号", "图片封面", "商品名称", "规格名称", "品牌", "一级分类","二级分类","三级分类", "商品京东价", "商品京东链接","规格京东价",  "规格京东链接","一键代发价", "每日供应量"]];
                    this.multipleSelection.filter(i=>i.Other_SerialNumber==this.form.Supplier_SerialNumber||i.Row_Status1!='2'&&i.Row_Status=='0').forEach(item => {
                        ws_data.push([
                            item.Article_SerialNumber,
                            item.Article_Code,
                            BASE_IMG + item.Picture_URL,
                            item.Article_Name,
                            item.Specifications_Name,
                            item.Brand_Name,
                            item.Classify_Name.split('-')[0],
                            item.Classify_Name.split('-')[1],
                            item.Classify_Name.split('-')[2],
                            item.JDCOM_Unit_Price,
                            item.JDCOM_URL,
                            item.JDCOM_Unit_Price1,
                            item.JDCOM_URL1,
                            item.Row_Status=='0'||item.Row_Status1=='2'?item.Purchase_Unit_Price:'',
                            item.Row_Status=='0'||item.Row_Status1=='2'?item.Total_stock:'',
                        ])
                    })
                    const ws = XLSX.utils.aoa_to_sheet(ws_data);
                    ws['!cols'] = [];
                    ws_data[0].forEach(item => {
                        ws['!cols'].push({ alignment: { horizontal: "center" }, wpx: 150 });
                    })
                    XLSX.utils.book_append_sheet(wb, ws, "商品列表");
                    XLSX.writeFile(wb, '商品列表' + (+new Date()) + ".xlsx");
                    this.$message({
                        message: '已导出该商品列表！',
                        type: 'success'
                    })    
                }).catch(() => { });
            } else {
                if (this.multipleSelection.length > 0) {
                    this.$message({
                        type: 'warning',
                        message: '当前选中商品暂无自建商品'
                    });
                }else{
                    this.$message({
                        type: 'warning',
                        message: '请选择商品后再导出'
                    });
                }
            }
        }
    },
})